package com.yunhe.rentcars.pro.controller.finance;




import com.yunhe.rentcars.pro.entity.finance.Finance;
import com.yunhe.rentcars.pro.entity.rent.Cars;
import com.yunhe.rentcars.pro.entity.system.Dept;
import com.yunhe.rentcars.pro.service.finance.FinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/11/25 0025.
 */
@Controller
@RequestMapping("/finance")
public class FinanceController {

    @Autowired
    private FinanceService financeService;

    @InitBinder
    public void initBinder(ServletRequestDataBinder binder){
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"),
                true));
    }


    @RequestMapping("/carsub")
    public String listCarSub(HttpServletRequest req, String deptname){

        List<Cars> cars = financeService.findCars(deptname);
        req.setAttribute("cars",cars);

        return "finance/listcarsub";
    }

    @RequestMapping("/monthsub")
    public String listMonthSub(HttpServletRequest req){
        List<Dept> depts = financeService.findDepts();
        req.setAttribute("depts",depts);
        return "finance/listmonthsub";
    }



    @RequestMapping("/listDataCarIncome")
    @ResponseBody
    public List<Finance> listDataCarIncome(String carcode, Date starttime, Date endtime){
        List<Finance> finances = financeService.incomeCarFinanceMsgs(carcode,starttime,endtime);
        return  finances;
    }

    @RequestMapping("/listDataCarExpense")
    @ResponseBody
    public List<Finance> listDataCarExpense(String carcode, Date starttime, Date endtime){
        List<Finance> finances = financeService.expenseCarFinanceMsgs(carcode,starttime,endtime);
        return  finances;
    }

    @RequestMapping("/listDataMonthIncome")
    @ResponseBody
    public List<Finance> listDataMonthIncome(String deptname, Date starttime, Date endtime){
        List<Finance> finances = financeService.incomeMonthFinanceMsgs(deptname,starttime,endtime);
        return  finances;
    }

    @RequestMapping("/listDataMonthExpense")
    @ResponseBody
    public List<Finance> listDataMonthExpense(String deptname, Date starttime, Date endtime){
        List<Finance> finances = financeService.expenseMonthFinanceMsgs(deptname,starttime,endtime);
        return  finances;
    }




}
